package auth

/**
 * @see http://enfranchisedmind.com/blog/posts/grails-taglibs/
 * @see http://grails.org/doc/latest/guide/6.%20The%20Web%20Layer.html#6.3%20Tag%20Libraries
 *
 */
class MainTagLib {
	
	static namespace = "auth"
	
	/**
	 * @author rocco
	 * 
	 * checks if user is logged in or not and returns
	 * login form or user-options accordingly
	 * 
	 * Usage in template: <auth:loginControl/>
	 * Requires partial template "/_loginForm.gsp"
	 */
	def loginControl = {
		if (session.user){
			// TODO: add more links like "delete account", "change password", "edit account"
			out << "Du bist eingeloggt als ${session.user.login} "
			out << """[${link(action:"logout", controller:"user"){"logout"}}]"""
		}
		else{
			out << render(template:'/loginForm')
		}
	}

}
